package com.files.controller;

import com.files.ReturnT;
import com.files.chain.FileChain;
import com.files.convert.MultipartFileToFileInfoConverter;
import com.files.model.FileInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class FileController {


    @Autowired
    MultipartFileToFileInfoConverter multipartFileToFileInfoConverter;

    @GetMapping("/upload")
    public ReturnT<String> upload(MultipartFile multipartFile){
        FileInfo fileInfo = multipartFileToFileInfoConverter.convert(multipartFile);
        FileChain.getListensers().stream().forEach(e->e.upload(fileInfo));
       return ReturnT.returnOK("");
    }
}
